package com.example.oppotest.service;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.example.oppotest.util.NetUtils;
import com.example.oppotest.util.oppoUtils;
import com.omni.ads.baseconfig.ResultDto;
import com.omni.ads.model.adscommunal.AdsConfigResp;
import org.apache.commons.collections4.map.ListOrderedMap;
import org.springframework.stereotype.Service;
import org.springframework.ui.ModelMap;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class OppoService {

    public ModelMap getConfigList() throws Exception {
        ModelMap map = new ModelMap();
//        ResultDto<List<AdsConfigResp>> response = oppoUtils.getConfigList();
//        map.put("json", JSON.toJSONString(response, SerializerFeature.PrettyFormat));
        HashMap<String, String> params = new HashMap<>();
        params.put("type", "EXTENSION_TYPE");
        params.put("ownerId", "1000347695");
        String msg = NetUtils.postXwwFormUrlEncoded(oppoUtils.productUrl + "/v3/communal/config/getList", oppoUtils.generateToken(), params);
        map.put("msg", msg);
        return map;
    }

    public ModelMap getPlan() throws Exception {
        ModelMap map = new ModelMap();
//        ResultDto<List<AdsConfigResp>> response = oppoUtils.getConfigList();
//        map.put("json", JSON.toJSONString(response, SerializerFeature.PrettyFormat));
        HashMap<String, String> params = new HashMap<>();
        params.put("planId", "217534513");
        String msg = NetUtils.postXwwFormUrlEncoded(oppoUtils.productUrl + "/v3/plan/get", oppoUtils.generateToken(), params);
        map.put("msg", msg);
        return map;
    }

    public ModelMap updatePlanStatus() throws IOException {
        ModelMap map = new ModelMap();
        HashMap<String, String> params = new HashMap<>();
        params.put("ownerId", "1000347695");
        params.put("planIds", "209417259");
        params.put("dayLimit", "1");
//        params.put("dayBudget", "40000");
        String msg = NetUtils.postXwwFormUrlEncoded(oppoUtils.productUrl + "/v3/plan/status", oppoUtils.generateToken(), params);
        map.put("msg", msg);
        return map;
    }


}
